package com.cloud.api.user.controller;

import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.api.base.BaseController;
import com.cloud.api.user.service.UserService;
import com.cloud.common.result.ExecuteResult;
import com.cloud.model.PlayUserClient;
import com.cloud.model.User;

import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

	@Autowired
	private UserService userService;

	/**
	 * 游客登录，如果不存在返回给一个令牌
	 * 
	 * @param tokenParam
	 * @return
	 */
	@GetMapping()
	public Mono<PlayUserClient> user(@RequestHeader Map<String, String> requestHeader) {
		String userId = getUserId(requestHeader);
		if(StringUtils.isEmpty(userId)) {
			userService.register(userId);
		}
		Mono<PlayUserClient> user = userService.findByIdInCache(userId);
		return user;
	}

}